package com.lhkj.ct.admin.modules.scheduling.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.scheduling.model.entity.TblScheMould;
import com.lhkj.ct.meta.modules.scheduling.service.ScheMouldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 排班模板 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-10-29
 */
@RestController
@RequestMapping("api/plat/scheduling/mould")
@Api(tags = {"4.3排班模板"})
@Validated
public class ScheMouldController {

    @Resource
    private ScheMouldService scheMouldService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页查询")
    @GetMapping("list")
    public ActionResult<IPage<TblScheMould>> list(TblScheMould mould, PageQuery pageQuery) {
        return ActionResult.success(scheMouldService.selectMouldPage(mould, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "模板详情")
    @GetMapping("{mouldId}/get")
    public ActionResult<TblScheMould> get(@PathVariable String mouldId) {
        return ActionResult.success(scheMouldService.getById(mouldId));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增")
    @PostMapping("insert")
    public ActionResult<Void> insert(@RequestBody TblScheMould mould) {
        return ActionResult.judge(scheMouldService.insert(mould));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "编辑")
    @PutMapping("update")
    public ActionResult<Void> update(@RequestBody TblScheMould mould) {
        return ActionResult.judge(scheMouldService.updateById(mould));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除", notes = "支持批量")
    @DeleteMapping("delete")
    public ActionResult<Void> delete(@NotEmpty(message = "请选择需要删除的模板") @RequestBody List<String> ids) {
        int res = scheMouldService.removeByIds(ids);
        return ActionResult.success(String.format("操作成功，共删除【%d】个排班模板", res));
    }
}
